Displays a standard dialog that allows the user to select a folder.
FileSelectFolder, OutputVar [, StartingFolder, Options, Prompt]
OutputVar | The name of the variable in which to store the user's selected folder. This will be made blank if the user cancels the dialog (i.e. does not wish to select a folder). If the user selects a root directory (such as C:\), OutputVar will contain a trailing backslash. If this is undesirable, remove it as follows: FileSelectFolder, Folder
StringRight, LastChar, Folder, 1
if LastChar = \
StringTrimRight, Folder, Folder, 1 ; Remove the trailing backslash. |
StartingFolder | If blank or omitted, the dialog's initial selection will be the user's My Documents folder (or possibly My Computer). A CLSID folder such as ::{20d04fe0-3aea-1069-a2d8-08002b30309d} (i.e. My Computer) may be specified start navigation at a specific special folder. Otherwise, the most common usage of this parameter in v1.0.36.03+ is an asterisk followed immediately by the absolute path of the drive or folder to be initially selected. For example, *C:\ would initially select the C drive. Similarly, *C:\My Folder would initially select that particular folder. The asterisk indicates that the user is permitted to navigate upward (closer to the root) from the starting folder. Without the asterisk, the user would be forced to select a folder inside StartingFolder (or StartingFolder itself). One benefit of omitting the asterisk is that StartingFolder is initially shown in a tree-expanded state, which may save the user from having to click the first plus sign. If the asterisk is present, upward navigation may optionally be restricted to a folder other than Desktop. This is done by preceding the asterisk with the absolute path of the uppermost folder followed by exactly one space or tab. In the following example, the user would not be allowed to navigate any higher than C:\My Folder (but the initial selection would be C:\My Folder\Projects): |
Options | One of the following numbers: 0: The options below are all disabled (except on Windows 2000, where the "make new folder" button might appear anyway). 1 (default): A button is provided that allows the user to create new folders. However, the button will not be present on Windows 95/98/NT. Add 2 to the above number to provide an edit field that allows the user to type the name of a folder. For example, a value of 3 for this parameter provides both an edit field and a "make new folder" button. If the user types an invalid folder name in the edit field, OutputVar will be set to the folder selected in the navigation tree rather than what the user entered, at least on Windows XP. This parameter can be an expression. |
Prompt | Text displayed in the window to instruct the user what to do. If omitted or blank, it will default to "Select Folder - %A_SCRIPTNAME%" (i.e. the name of the current script). |
ErrorLevel is set to 1 if the user dismissed the dialog without selecting a file (such as by pressing the Cancel button). It is also set to 1 if the system refused to show the dialog (rare). Otherwise, it is set to 0.
A GUI window may display a modal folder-selection dialog by means of Gui +OwnDialogs. A modal dialog prevents the user from interacting with the GUI window until the dialog is dismissed.
Known limitation: A timer that launches during the display of a FileSelectFolder dialog will postpone the effect of the user's clicks inside the dialog until after the timer finishes. To work around this, avoid using timers whose subroutines take a long time to finish, or disable all timers during the dialog:
Thread, NoTimers FileSelectFolder, OutputVar,, 3 Thread, NoTimers, false
FileSelectFile, MsgBox, InputBox, ToolTip, GUI, CLSID List, FileCopyDir, FileMoveDir, SplitPath
Also, the operating system offers two standard dialogs that prompt the user to pick a font and/or color. These dialogs can be displayed via DllCall() as demonstrated in the forum topics ChooseFont and ChooseColor.
FileSelectFolder, OutputVar, , 3
if OutputVar =
MsgBox, You didn't select a folder.
else
MsgBox, You selected folder "%OutputVar%".
CLSID Example:
FileSelectFolder, OutputVar, ::{20d04fe0-3aea-1069-a2d8-08002b30309d} ; My Computer.